<template>
	<view class="contain">
		<view class="title">
			选课
		</view>
		<scroll-view class="list" scroll-y="true">
			<view class="items" v-show="item.isShow" v-for="(item,index) in selects">
				<view class="time">
					<view class="start">
						开始时间：{{item.start_time.replace("T"," ")}}
					</view>
					<view class="end">
						结束时间：{{item.end_time.replace("T"," ")}}
					</view>
				</view>
				<u-swipe-action>
					<u-swipe-action-item :options="options" @click="select(index)">
						<view class="info">
							<view class="coursename">
								{{item.course.name}}
							</view>

							<view class="teachername">
								{{item.teacher}}
							</view>
							<view class="number">
								剩余{{item.max_num-item.num}}人
							</view>
						</view>
						<view class="info2">
							<view class="category">
								{{item.course.category}}

							</view>
							<view class="credit">
								学分：{{item.course.credit}}
							</view>
							<view class="hour">
								总学时：{{item.course.total_hours}}
							</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>

			</view>
		</scroll-view>

	</view>
</template>

<script>
	import api from '@/api/index.js'; // 引入api
	export default {
		data() {
			return {
				selects: {

				},
				options: [{
					text: '选课',
					style: {
						backgroundColor: '#f56c6c'
					}
				}]
			};
		},
		onLoad() {
			let token = uni.getStorageSync("token")
			api.getSelect(token).then((res) => {
				if (res.code === 1) {
					this.selects = res.data
					for (let i = 0; i < this.selects.length; i++) {
						this.$set(this.selects[i], "isShow", true)
					}
				} else {
					uni.showModal({
						content: res.errors
						
					})
				}
			}).catch((err) => {

			})
		},
		methods: {
			select(index) {
				// console.log(index)
				let token = uni.getStorageSync("token")
				let data = {
					select_id: this.selects[index].id
				}
				api.selectClass(token, data).then((res) => {
					console.log(res)
					if (res.code === 1) {
						this.selects[index].isShow = false
					} else {
						uni.showModal({
							content: res.errors
						})
					}


				}).catch((err) => {

				})
			}
		}
	}
</script>

<style lang="less">
	.contain {
		.title {
			height: 100px;
			line-height: 100px;
			background-color: #a62618;
			text-align: center;
			color: white;
			font-size: 25px;
		}

		.list {
			background-color: white;
			height: calc(100vh - 200px);
			// margin-top: 12px;
			font-size: 12px;
			font-size:10px ;
			.items {
				// margin-bottom: 10px;

				.time {
					height: 30px;
					line-height: 40px;
					background-color: #E5E5E5;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					
					.start {
						width: 350rpx;
					}

					.end {
						width: 350rpx;
						color: red;
					}
				}

				.info {
					font-weight: bold;
					font-size:10px;
					height: 50px;
					// line-height: 80px;
					background-color: #F4F4F5;
					display: flex;
					align-items: center;
					justify-content: space-around;

					.coursename {
						width: 480rpx;
					}

					.teachername {
						width: 150rpx;
					}

					.number {
						width: 100rpx;
						color: #767A82;
					}

				}

				.info2 {
					font-weight: bold;
					height: 20px;
					// line-height: 80px;
					font-size: 10px;
					background-color: white;
					display: flex;
					align-items: center;
					justify-content: space-between;
					// margin: 0 20rpx;

					.category {
						width: 200rpx;
					}

					.credit {
						width: 100rpx;
					}

					.hour {
						hour: 100rpx;
					}
				}
			}
		}

	}
</style>
